package com.rui.singleton.model;

/**
 * 懒汉式
 * <p>
 * 双重检验锁(double check lock)(DCL)
 *
 * @author ZhangRui
 * @date 2023/03/02 10:39
 **/
public class DCLSingleton {

    private volatile static DCLSingleton dclSingleton;

    private DCLSingleton() {

    }

    /**
     * 特点:安全且在多线程情况下能保持高性能
     *
     * @return
     */
    public static DCLSingleton getInstance() {
        if (dclSingleton == null) {
            synchronized (DCLSingleton.class) {
                if (dclSingleton == null) {
                    dclSingleton = new DCLSingleton();
                }
            }
        }
        return dclSingleton;
    }
}
